<!DOCTYPE html>
<!-- saved from url=(0028)http://www.nyypt.cn/Iot/Home -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width">
    <title>智慧农业物联网</title>
    <link href="./resource/ioc/base.css" rel="stylesheet">
    <link href="./resource/ioc/index.css" rel="stylesheet">
    <script src="./resource/ioc/jquery-1.11.3.min.js.下载"></script>
    <script src="./resource/ioc/layer.js.下载"></script><link rel="stylesheet" href="./resource/ioc/layer.css" id="layui_layer_skinlayercss" style="">
    <script src="./resource/ioc/echarts.js.下载"></script>
    <script src="./resource/ioc/jquery.blockUI.js.下载"></script>
    <script src="./resource/ioc/pb.js.下载"></script>
    <script src="./resource/ioc/winddirection.js.下载"></script>
    <script src="./resource/ioc/ckplayer.js.下载"></script>
    <script src="./resource/ioc/jquery.ztree.core.min.js.下载"></script>
    <link href="./resource/ioc/zTreeStyle.css" rel="stylesheet">
    <script type="text/javascript">
        var tag = 1;
        var tag2 = 1;
    </script>
    <style>
        .ztree {
            margin-top: 11px;
            border: 1px solid #617775;
            background: #f0f6e4;
            overflow-y: scroll;
            overflow-x: auto;
        }

        .node_name {
            font-size: 14px;
        }

        .water_main > div, .temp_l > div {
            cursor: pointer;
        }

        .num, .water, .temp, .content {
            display: none;
        }
    </style>
</head>
<body>
    <!-- 头部开始 -->
    <div class="top">

<div class="wrap clearfix">
    <h1 class="logo"><a href="http://www.nyypt.cn/Iot/Home"></a></h1>
    <span class="lo_name">智慧农业物联网</span>
    <div class="top_r">
        <ul class="clearfix">
            <li><a target="_blank" href="http://www.nyypt.cn/Formula/Index">配方管理</a></li>
            <li><a target="_blank" href="http://www.nyypt.cn/IrrigationTask/Task/TaskList">任务管理</a></li>
            <li><a target="_blank" href="http://www.nyypt.cn/Iot/Group/GroupList">分组管理</a></li>
            <li><a target="_blank" href="http://www.nyypt.cn/Iot/Area/AreaList">区域管理</a></li>
            <li><a target="_blank" href="http://www.nyypt.cn/Settings/Alarm">报警设置</a></li>
            <li><a target="_blank" a="" href="javascript:;">自动化设置</a></li>
            <li><a target="_blank" a="" href="javascript:;">帮助与文档</a></li>
            <li><a href="javascript:;">hghuser</a></li>
            <li><a href="http://www.nyypt.cn/Login">退出</a></li>
        </ul>
    </div>
</div>

        <div class="line" style="height:1px;"></div>
        <div class="wrap clearfix infor">
            <p class="infor_main">传感器数量为：<i id="sensor">6</i>控制设备数量为：<i id="controllercount">2</i></p>
            <div class="infor_r">
                <label for="">当前区域：</label>
                <select name="" id="area"><option value="203" groupid="203" groupname="黄杆湖" category="Group" disabled="disabled">黄杆湖</option><option value="219" userid="b02b0cbe-95ee-4091-b96f-a68f398ecee1" groupid="203" groupname="黄杆湖" category="Area">&nbsp;&nbsp;&nbsp;&nbsp;黄杆湖</option></select>
            </div>
            <div class="infor_r" style="margin-right:70px;">
                <label for="">用户：</label>
                
                <span id="citySel" style="font-size: 14px">黄杆湖</span>
                <a style="margin-left:10px;" id="menuBtn" href="http://www.nyypt.cn/Iot/Home#" onclick="showMenu(); return false;">切换</a>
            </div>
        </div>
    </div>
    
    <!-- 主要内容 -->
    <div style="margin-top:118px;"></div>
    <div class="content wrap clearfix" style="margin-top: 0px; display: block;">
        <div class="left content_l">
            <div class="clearfix conl_top">
                <div class="line2 left"></div>
                <div class="left  con1">
                    <label for="">监控视频：</label>
                    <select name="" id="Cameras"><option value="rtmp://rtmp.open.ys7.com/openlive/a04897299cdf45a2b30f498bb67d5cfd" channelno="1" deviceserial="107970598">黄杆湖1号</option></select>
                </div>
                <div class="right con2">
                    <ul class="left">
                        <li><a href="javascript:;" class="a1" onclick="StartCameraPtz(0)"></a></li>
                        <li><a href="javascript:;" class="a2" onclick="StartCameraPtz(1)"></a></li>
                        <li><a href="javascript:;" class="a7" onclick="StartCameraPtz(-100)"></a></li>
                        <li><a href="javascript:;" class="a3" onclick="StartCameraPtz(2)"></a></li>
                        <li><a href="javascript:;" class="a4" onclick="StartCameraPtz(3)"></a></li>
                        <li><a href="javascript:;" class="a5" onclick="StartCameraPtz(8)"></a></li>
                        <li><a href="javascript:;" class="a6" onclick="StartCameraPtz(9)"></a></li>
                    </ul>
                </div>
            </div>
            <div class="video_img" id="div_video" style="height: 365px;">
                
                <script src="./resource/ioc/cyberplayer.min.js.下载"></script>
            <div id="playercontainer"><object pluginspage="http://www.macromedia.com/go/getflashplayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=11,3,0,0" width="550px" height="365px" id="video" name="video" align="middle"><param name="allowScriptAccess" value="always"><param name="allowFullScreen" value="true"><param name="quality" value="high"><param name="bgcolor" value="#FFF"><param name="wmode" value="transparent"><param name="movie" value="/Scripts/ckplayer/ckplayer.swf"><param name="flashvars" value="f=rtmp://rtmp.open.ys7.com/openlive/a04897299cdf45a2b30f498bb67d5cfd&amp;c=1&amp;p=1"><embed allowscriptaccess="always" allowfullscreen="true" quality="high" bgcolor="#FFF" wmode="transparent" src="./resource/ioc/ckplayer/ckplayer.swf" flashvars="f=rtmp://rtmp.open.ys7.com/openlive/a04897299cdf45a2b30f498bb67d5cfd&amp;c=1&amp;p=1" width="550px" height="365px" name="video" id="video" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></object></div></div>
        </div>
        <div class="right content_r">
            <div class="conr_top clearfix">
                <i class="line3 left"></i>
                <p class="left">设备控制</p>
                <p onclick="RefreshData(&#39;&#39;)" style="margin-right:20px;cursor:pointer;" class="right">刷新</p>
            </div>
            <div class="control clearfix" style="overflow-y: auto; max-height: 375px; height: 375px;" id="controller">
                <div class="left control_main">
                    <ul id="tabNav"><li id="1c5a345b-9139-479c-a6b9-bee84968c357"><div style="display:table;"><p class="" style="display:table-cell;line-height:20px;vertical-align: middle;">喂养机</p><span class="imgs right"><i></i><span class="open isopen" deviceid="1c5a345b-9139-479c-a6b9-bee84968c357" slottype="1"></span><span class="close c" deviceid="1c5a345b-9139-479c-a6b9-bee84968c357" slottype="1"></span></span></div></li></ul>
                </div>
                <div class="notice-bd">
                    <ul id="tabList">
                        <li>
                            <table id="controllerlog" style="width: 300px"></table>
                        </li>
                    </ul>
                </div>
                <div class="right control_main">
                    <ul id="tabNav2"><li id="b610dc58-f099-494f-8460-017f17e4710f"><div style="display:table;"><p class="" style="display:table-cell;line-height:20px;vertical-align: middle;">增氧泵</p><span class="imgs right"><i></i><span class="open o" deviceid="b610dc58-f099-494f-8460-017f17e4710f" slottype="1"></span><span class="close isclose" deviceid="b610dc58-f099-494f-8460-017f17e4710f" slottype="1"></span></span></div></li></ul>
                </div>
            </div>
        </div>
    </div>
    <div class="num wrap" style="display: block;">
        <div class="num_t clearfix">
            <i class="line3 left"></i>
            <p class="left">实时数据</p>
            <p onclick="RefreshData(&#39;&#39;)" style="margin-right:20px;cursor:pointer;" class="right">刷新</p>
        </div>
        <div class="num_main">
            <ul class="clearfix" id="DeviceList"><li class="num_info" id="0f0771f6-2714-4992-8428-6922802d4912"><div class="num_top"><img src="./resource/ioc/s2817.png" width="36" alt=""><p>水质溶解氧</p></div><div class="qushi"><p>0.00</p><img src="./resource/ioc/rup_icon.png" height="9" width="17" alt=""></div><p class="tem" style="color: #146133;">8.3<i>mg/L</i></p><p class="tiao"><span class="t1">4</span><span class="t2">20</span></p><p class="normal" style="color: #146133;">正常</p><p class="time" style="font-size:medium;">1分钟前</p><div class="btn"><button class="left" onclick="SetSetting()">报警设置</button><button class="right" onclick="GetHistory(&#39;0f0771f6-2714-4992-8428-6922802d4912&#39;,&#39;水质溶解氧&#39;,&#39;1&#39;,&#39;30&#39;)">历史数据</button></div></li> <li class="num_info" id="3068b895-09f2-4a8c-a1f1-32b6c99dcaa0"><div class="num_top"><img src="./resource/ioc/s1537.png" width="36" alt=""><p>水质电导率</p></div><div class="qushi"><p>0.00</p><img src="./resource/ioc/rup_icon.png" height="9" width="17" alt=""></div><p class="tem" style="color: #146133;">283.79<i>us/cm</i></p><p class="tiao" style="background-color:white"><span class="t1"></span><span class="t2"></span></p><p class="normal" style="color: #146133;"></p><p class="time" style="font-size:medium;">1分钟前</p><div class="btn"><button class="left" onclick="SetSetting()">报警设置</button><button class="right" onclick="GetHistory(&#39;3068b895-09f2-4a8c-a1f1-32b6c99dcaa0&#39;,&#39;水质电导率&#39;,&#39;1&#39;,&#39;29&#39;)">历史数据</button></div></li> <li class="num_info" id="3c978f68-3fca-4d77-b7a3-e431d4712db6"><div class="num_top"><img src="./resource/ioc/s5121.png" width="36" alt=""><p>水质铵根离子</p></div><div class="qushi"><p>0.00</p><img src="./resource/ioc/rup_icon.png" height="9" width="17" alt=""></div><p class="tem" style="color: #146133;">0<i>ppm</i></p><p class="tiao"><span class="t1"></span><span class="t2">0.02</span></p><p class="normal" style="color: #146133;">正常</p><p class="time" style="font-size:medium;">1分钟前</p><div class="btn"><button class="left" onclick="SetSetting()">报警设置</button><button class="right" onclick="GetHistory(&#39;3c978f68-3fca-4d77-b7a3-e431d4712db6&#39;,&#39;水质铵根离子&#39;,&#39;1&#39;,&#39;18&#39;)">历史数据</button></div></li> <li class="num_info" id="86044502-1427-41a0-bf08-37967e1ddf58"><div class="num_top"><img src="./resource/ioc/s6145.png" width="36" alt=""><p>凯氏氮</p></div><div class="qushi"><p>0.00</p><img src="./resource/ioc/rup_icon.png" height="9" width="17" alt=""></div><p class="tem" style="color: #ff0000;">3<i>ppm</i></p><p class="tiao"><span class="t1">0.05</span><span class="t2">10000</span></p><p class="normal" style="color: #ff0000;">报警</p><p class="time" style="font-size:medium;">1分钟前</p><div class="btn"><button class="left" onclick="SetSetting()">报警设置</button><button class="right" onclick="GetHistory(&#39;86044502-1427-41a0-bf08-37967e1ddf58&#39;,&#39;凯氏氮&#39;,&#39;1&#39;,&#39;19&#39;)">历史数据</button></div></li> <li class="num_info spe" id="97dd021a-489d-4d79-aec5-9a31a63e0297"><div class="num_top"><img src="./resource/ioc/s513.png" width="36" alt=""><p>水质PH</p></div><div class="qushi"><p>0.00</p><img src="./resource/ioc/rup_icon.png" height="9" width="17" alt=""></div><p class="tem" style="color: #146133;">6.81<i></i></p><p class="tiao" style="background-color:white"><span class="t1"></span><span class="t2"></span></p><p class="normal" style="color: #146133;"></p><p class="time" style="font-size:medium;">1分钟前</p><div class="btn"><button class="left" onclick="SetSetting()">报警设置</button><button class="right" onclick="GetHistory(&#39;97dd021a-489d-4d79-aec5-9a31a63e0297&#39;,&#39;水质PH&#39;,&#39;1&#39;,&#39;7&#39;)">历史数据</button></div></li> <li class="num_info" id="c251af0a-ce48-43c8-ae61-041770752b30"><div class="num_top"><img src="./resource/ioc/s5889.png" width="36" alt=""><p>水质钾离子</p></div><div class="qushi"><p>0.00</p><img src="./resource/ioc/rup_icon.png" height="9" width="17" alt=""></div><p class="tem" style="color: #146133;">0<i>ppm</i></p><p class="tiao" style="background-color:white"><span class="t1"></span><span class="t2"></span></p><p class="normal" style="color: #146133;"></p><p class="time" style="font-size:medium;">1分钟前</p><div class="btn"><button class="left" onclick="SetSetting()">报警设置</button><button class="right" onclick="GetHistory(&#39;c251af0a-ce48-43c8-ae61-041770752b30&#39;,&#39;水质钾离子&#39;,&#39;1&#39;,&#39;17&#39;)">历史数据</button></div></li> </ul>
        </div>
    </div>

    <div class="water wrap" style="display: none;">
        <div class="num_t clearfix">
            <i class="line3 left"></i>
            <p class="left">水肥机</p>
            <p onclick="RefreshData(&#39;&#39;)" style="margin-right:20px;cursor:pointer;" class="right">刷新</p>
        </div>
        <div class="water_main" style="display: none;"></div>
    </div>
    <div class="temp wrap" style="margin-bottom: 30px; display: none;">
        <div class="num_t clearfix">
            <i class="line3 left"></i>
            <p class="left">气象站</p>
            <p onclick="RefreshData(&#39;&#39;)" style="margin-right:20px;cursor:pointer;" class="right">刷新</p>
        </div>
        <div class="temp_infor"></div>
    </div>



    <div class="div_footer" style="padding: 30px; text-align: center; background: #f0f0f0; margin-top: 20px;">
    <section>
        Copyright ©2013-2016 zaxh.cn. All Rights Reserved. 左岸芯慧 版权所有
    </section>
</div>
;
    <div style="display: none; border: 2px solid rgb(20, 97, 51); width: 640px; height: 326.5px;" id="dialog_add">
        <div class="clearfix" style="font: 14px/40px 微软雅黑;padding: 0 20px;">
            
            <a href="javascript:;" onclick="Test()" class="right high" style="color:#169bd5;">高级</a>
        </div>
        <div style="width: 640px; height: 286.5px;" id="main"></div>
    </div>
    <div id="menuContent" class="menuContent" style="display:none; position: absolute;">
        <ul id="treeDemo" class="ztree"><li id="treeDemo_1" class="level0" tabindex="0" hidefocus="true" treenode=""><span id="treeDemo_1_switch" title="" class="button level0 switch root_docu" treenode_switch=""></span><a id="treeDemo_1_a" class="level0 curSelectedNode" treenode_a="" onclick="" target="_blank" style="" title="黄杆湖"><span id="treeDemo_1_ico" title="" treenode_ico="" class="button ico_docu" style="width:0px;height:0px;"></span><span id="treeDemo_1_span" class="node_name">黄杆湖</span></a></li></ul>
    </div>


<script>
    var layer_i;
    setInterval("RefreshData('')", 300000);
    var aeraId, areaName, groupId, groupName, operateCategory;
    var DeviceId = "";
    var SlotId = "";
    var TypeID = "";
    var echarswidth;
    var state = 0;
    var myPlayer;

    var ExcelDeviceId;
    $(function () {
        //获取用户树
        GetUserTree();
        echarswidth = $(window).width() / 2;
        var height = $(window).height() / 2;
        $("#dialog_add").width(echarswidth).height(height);
        $("#main").width(echarswidth).height(height - 40);
        //var areaId = $("#area").val();
        ////获取用户区域下的设备列表
        //GetArea(areaId,GetUserId());
        $("#area")
            .change(function () {
                GetAlarmSettingList(GetUserId());
                GetArea($(this).val(), GetUserId());
            });
        $("#Cameras")
            .change(function () {
                SetPlayer($(this).val());
            });
        $("body")
            .bind("click",
                function (event) {
                    if ($("#controller").length != 0) {
                        if ($(event.target).parents("#controller").length == 0) {
                            var tabNav = document.getElementById('tabNav').getElementsByTagName('li');
                            var tabNav2 = document.getElementById('tabNav2').getElementsByTagName('li');
                            var tabList = document.getElementById('tabList').getElementsByTagName('li');
                            for (var j = 0; j < tabNav.length; j++) {
                                tabNav[j].className = '';
                            }
                            for (var j = 0; j < tabNav2.length; j++) {
                                tabNav2[j].className = '';
                                $(tabNav2[j]).find("div").css("border", "1px solid #9dafb0");
                            }
                            tabList[0].className = '';
                            $(".notice-bd").css("display", "none");
                        }
                    }
                });
        $(document)
            .on("click",
                ".o",
                function (e) { //修改成这样的写法
                    var DeviceID = $(this).attr("DeviceID");
                    var SlotType = $(this).attr("SlotType");
                    var Action = "OPEN";
                    e.stopPropagation();
                    ControlRelay(DeviceID, Action, SlotType);
                });
        $(document)
            .on("click",
                ".s",
                function (e) { //修改成这样的写法
                    var DeviceID = $(this).attr("DeviceID");
                    var SlotType = $(this).attr("SlotType");
                    var Action = "STOP";
                    e.stopPropagation();
                    ControlRelay(DeviceID, Action, SlotType);
                });
        $(document)
            .on("click",
                ".c",
                function (e) { //修改成这样的写法
                    var DeviceID = $(this).attr("DeviceID");
                    var SlotType = $(this).attr("SlotType");
                    var Action = "CLOSE";
                    e.stopPropagation();
                    ControlRelay(DeviceID, Action, SlotType);
                });

        $(document)
            .on("click",
                "#tabNav li",
                function (e) { //修改成这样的写法
                    GetControllerLog($(this).attr("id"));
                    $(".notice-bd").css("right", "0");
                    $(".notice-bd").css("display", "block");
                    $("#tabNav li").removeClass("current");
                    $("#tabNav2 li").removeClass("current2").find("div").css("border", "1px solid #9dafb0");;
                    $(this).addClass("current");
                    $("#tabList li").addClass("current");

                    var $controller = $("#controller");
                    var nScrollHight = $controller[0].scrollHeight;
                    var nScrollTop = $controller[0].scrollTop;
                    if ($("#tabNav li").length >= 6) {
                        $(this).width(299);
                        var height = $("#controller").scrollTop(); //滚动条已滚动的距离
                        var b = $(this).position().top; //当前li距父级div的距离（父级div滚动的距离不算）
                        if (b < 0) { //li滚动到父级div顶部之外
                            tag = 1;
                            if ((b + height) > 0) {
                                $("#controller").scrollTop((b + height));
                                $(".notice-bd").css("top", (b + height));
                            } else {
                                $("#controller").scrollTop(0);
                                $(".notice-bd").css("top", 0);
                            }
                        } else if (tag == 0 && ($("#tabNav li").index(this) + 1) == $("#tabNav li").length) {

                        } else if (b > 305) { //li距离父级div的距离超过5个li的总高度（61*5），如果被点击，需要滚动条往下滚一定距离才能完整显示被点击的li
                            if (($("#tabNav li").index(this) + 1) == $("#tabNav li").length) { //最后一个
                                tag = 0;
                                $controller.scrollTop(nScrollHight - nScrollTop);
                                nScrollTop = $controller[0].scrollTop;
                                $(".notice-bd").css("top", nScrollTop - 2);
                            } else {
                                var tmp = b - 305;
                                $controller.scrollTop(nScrollTop + tmp);
                                $(".notice-bd").css("top", height + tmp);
                            }
                        } else {
                            tag = 1;
                            $(".notice-bd").css("top", height);
                        }
                    } else {
                        $(".notice-bd").css("right", "0");
                    }
                });
        $(document)
            .on("click",
                "#tabNav2 li",
                function (e) { //修改成这样的写法
                    GetControllerLog($(this).attr("id"));
                    $(".notice-bd").css("display", "block");
                    if ($("#tabNav li").length > 6) {
                        $(".notice-bd").css("right", "299px");
                    } else {
                        $(".notice-bd").css("right", "299px");
                    }
                    $("#tabNav li").removeClass("current");
                    $("#tabNav2 li").removeClass("current2").find("div").css("border", "1px solid #9dafb0");;
                    $(this).addClass("current2").find("div").css("border", "0px solid #9dafb0");
                    $("#tabList li").addClass("current");
                    var $controller = $("#controller");
                    var nScrollHight = $controller[0].scrollHeight;
                    var nScrollTop = $controller[0].scrollTop;
                    if ($("#tabNav li").length > 6) {
                        $(this).width(299);
                        var height = $("#controller").scrollTop();
                        var b = $(this).position().top;
                        if (b < 0) {
                            tag2 = 1;
                            if ((b + height) > 0) {
                                $("#controller").scrollTop((b + height));
                                $(".notice-bd").css("top", (b + height));
                            } else {
                                $("#controller").scrollTop(0);
                                $(".notice-bd").css("top", 0);
                            }
                        } else if (tag2 == 0 && ($("#tabNav2 li").index(this) + 1) == $("#tabNav2 li").length) {

                        } else if (b > 305) {
                            if (($("#tabNav2 li").index(this) + 1) == $("#tabNav li").length) {
                                tag2 = 0;
                                $controller.scrollTop(nScrollHight - nScrollTop);
                                nScrollTop = $controller[0].scrollTop;
                                $(".notice-bd").css("top", nScrollTop - 2);
                            }
                            else {
                                var tmp = b - 305;
                                $controller.scrollTop(nScrollTop + tmp);
                                $(".notice-bd").css("top", height + tmp);
                            }
                        } else {
                            tag2 = 1;
                            $(".notice-bd").css("top", height);
                        }
                    }
                });
    });
    //控制摄像头
    function StartCameraPtz(direction) {
        $.ajax({
            url: "/Iot/Home/StartCameraPtz",
            type: "post",
            dataType: "json",
            data: {
                DeviceSerial: $("#Cameras").find("option:selected").attr("deviceserial"),
                ChannelNo: $("#Cameras").find("option:selected").attr("channelno"),
                Direction: direction,
                Speed: 1
            },
            success: function (re) {
                if (typeof (re.Msg) != "undefined") {
                    location.href = '/Login/Login';
                }
            }
        });
    }

    //获取用户报警信息
    function GetAlarmSettingList(userId) {
        var count = $("#" + userId).length;
        if (count == 0) {
            $("body").append("<span id=" + userId + "></span>");
            $.ajax({
                beforeSend: function () { layer_i = layer.msg('加载中...', { icon: 16, shade: 0.01, time: 60 * 1000 }); },
                url: '/Settings/alarm/GetAlarmSettingList',
                type: "post",
                dataType: "json",
                async: false,
                data: { UserId: userId, pageSize: 1000, pageIndex: 1 },
                success: function (re) {
                    if (re.items != null) {
                        $.each(re.items, function (i, item) {
                            $("body").append("<span id=" + item.DeviceID + item.ThreatName + " EnableHigh=" + (item.EnableHigh == true ? "1" : "0") + " HighValue=" + item.HighValue + " EnableLow=" + (item.EnableLow == true ? "1" : "0") + " LowValue=" + item.LowValue + "></span>");
                        });
                    }
                },
                complete: function () {
                    layer.close(layer_i);
                }
            });
        }
    }

    //获取用户区域分组的列表
    function GetUserAreaList(userId) {
        $("#area").html("");
        $.ajax({
            beforeSend: function () { layer_i = layer.msg('加载中...', { icon: 16, shade: 0.01 }); },
            url: "/Iot/Home/GetUserAreaList",
            type: "post",
            dataType: "text",
            async: false,
            data: { UserId: userId },
            success: function (re) {
                $("#area").html(re);
            },
            complete: function () {
                layer.close(layer_i);
            }
        });
        if ($("#area").val() != null) {
            GetAlarmSettingList(GetUserId());
            GetArea($("#area").val(), GetUserId());
        }
    }

    //获取用户树形列表
    function GetUserTree() {
        var setting = {
            view: {
                dblClickExpand: false,
                showIcon: false,
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick: onClick
            }
        };
        $.ajax({
            url: "/Iot/Home/GetUserTree",
            type: "post",
            dataType: "json",
            async: false,
            success: function (re) {
                $.fn.zTree.init($("#treeDemo"), setting, re);
                //var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                //var node = treeObj.getNodeByParam("id", "370000");
                //treeObj.selectNode(node);
                //setting.callback.onClick = onClick;
            }
        });
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        //获取节点
        var nodes = treeObj.getNodes();
        //alert(nodes.length);
        if (nodes.length > 0) {
            var node = treeObj.selectNode(nodes[0]);
            var cityObj = $("#citySel");
            //cityObj.attr("value", nodes[0].name);
            cityObj.text(nodes[0].name);
            GetUserAreaList(nodes[0].id);
            //setting.callback.onClick = onClick;
        }
    }
    //////下拉列表
    function beforeClick(treeId, treeNode) {
        var check = (treeNode && !treeNode.isParent);
        //alert(treeNode.test);
        if (!check) alert("只能选择城市...");
        return check;
    }
    function onClick(e, treeId, treeNode) {
        hideMenu();
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
        nodes = zTree.getSelectedNodes(),
        v = "";
        nodes.sort(function compare(a, b) { return a.id - b.id; });
        for (var i = 0, l = nodes.length; i < l; i++) {
            v += nodes[i].name + ",";
        }
        if (v.length > 0) v = v.substring(0, v.length - 1);
        var cityObj = $("#citySel");
        cityObj.text(v);
        //cityObj.attr("value", v);
        //alert(treeNode.id);
        GetUserAreaList(treeNode.id);
    }
    function showMenu() {
        var cityObj = $("#citySel");
        var cityOffset = $("#citySel").offset();
        //var a = $("#test").offset().left;
        $("#menuContent").css({ left: cityOffset.left + "px", top: cityOffset.top + cityObj.outerHeight() + "px" }).slideDown("fast");

        $("body").bind("mousedown", onBodyDown);
    }
    function hideMenu() {
        $("#menuContent").fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }
    function onBodyDown(event) {
        if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
            hideMenu();
        }
    }
    ///////下拉列表
    function RefreshData(filters) {

        var DeviceSerial = $("#Cameras").find("option:selected").attr("deviceserial");
        var ChannelNo = $("#Cameras").find("option:selected").attr("channelno");
        if (DeviceSerial == undefined)
            DeviceSerial = 0;
        if (ChannelNo == undefined)
            ChannelNo = 0;
        $.ajax({
            beforeSend: function () {
                //console.log("layer.msg")
                layer_i = layer.msg('加载中...', { icon: 16, shade: 0.01, time: 60 * 1000 });
            },
            url: '/Iot/Home/AreaTree_NodeMouse',
            data: { AreaID: $("#area").val(), DeviceSerial: DeviceSerial, ChannelNo: ChannelNo, UserId: GetUserId(), Filters: filters },
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (typeof (result.Msg) != "undefined") {
                    location.href = '/Login';
                }
                $("#tabNav2").html("");
                $("#tabNav").html("");
                var j = 0;
                var k = 0;
                $.each(result.item, function (i) {
                    if (result.item[i].DeviceCategory == "SENSOR") {
                        if (result.item[i].DeviceTypeID != 1002) {
                            var data = result.item[i].Slots[0].LatestData.Close == null ? "暂无数据" : result.item[i].Slots[0].LatestData.Close + "<b>" + result.item[i].Slots[0].ValueUnit + "</b>";
                            var error = "146133";
                            if (result.item[i].Slots[0].ThreatLevel != -1 && result.item[i].Slots[0].ThreatLevel != 0)
                                error = "ff0000";
                            var Differ = ((result.item[i].Slots[0].LatestData.Close * 1000 - result.item[i].Slots[0].LatestData.Close * 1000) / 1000).toFixed(2);

                            if (Differ >= 0) {
                                $("#" + result.item[i].DeviceID + ">.qushi p").text(SensorNumException(Differ)).css("color", "#e36243");
                                $("#" + result.item[i].DeviceID + ">.qushi img").attr("src", "/images/IotHome/rup_icon.png");
                            }
                            else {
                                $("#" + result.item[i].DeviceID + ">.qushi p").text(SensorNumException(Differ)).css("color", "#146133");
                                $("#" + result.item[i].DeviceID + ">.qushi img").attr("src", "/images/IotHome/gdown_icon.png");
                            }

                            $("#" + result.item[i].DeviceID + ">.tem").css({ "color": "#" + error }).html(SensorNumException(result.item[i].Slots[0].LatestData.Close) + "<i>" + NullEmpty(result.item[i].Slots[0].ValueUnit) + "</i>");
                            $("#" + result.item[i].DeviceID + ">.normal").css({ "color": "#" + error }).text(NullEmpty(result.item[i].Slots[0].ThreatName));
                            $("#" + result.item[i].DeviceID + ">.time").text(result.item[i].Slots[0].LatestData.Time);
                            //2017-7-12 xyc 刷新数据重新绑定报警信息
                            var EnableHigh = $("#" + result.item[i].DeviceID + result.item[i].Slots[0].ThreatName).attr("enablehigh");
                            var HighValue = $("#" + result.item[i].DeviceID + result.item[i].Slots[0].ThreatName).attr("highvalue");
                            var EnableLow = $("#" + result.item[i].DeviceID + result.item[i].Slots[0].ThreatName).attr("enablelow");
                            var LowValue = $("#" + result.item[i].DeviceID + result.item[i].Slots[0].ThreatName).attr("lowvalue");

                            if (EnableHigh == undefined || EnableHigh == 0)
                                HighValue = "";
                            if (EnableLow == undefined || LowValue == 0)
                                LowValue = "";

                            if (HighValue != "" && LowValue != "") {
                                var hv = parseInt(HighValue);
                                var lv = parseInt(LowValue);
                                
                                if (hv < lv) {
                                    $("#" + result.item[i].DeviceID + ">.tiao").html("<span class=\"t1\">" + HighValue + "</span><span class=\"t2\">" + LowValue + "</span>");
                                }
                                else {
                                    $("#" + result.item[i].DeviceID + ">.tiao").html("<span class=\"t1\">" + LowValue + "</span><span class=\"t2\">" + HighValue + "</span>");
                                }
                            }
                            else {
                                if (LowValue != "" || HighValue != "") {
                                    
                                    $("#" + result.item[i].DeviceID + ">.tiao").html("<span class=\"t1\">" + HighValue + "</span><span class=\"t2\">" + LowValue + "</span>");
                                    
                                }
                                else {
                                    $("#" + result.item[i].DeviceID + ">.tiao").html("<span class=\"t1\">" + LowValue + "</span><span class=\"t2\">" + HighValue + "</span>").css("background-color","white");
                                }
                            }

                        }
                    }
                        //气象站
                    else if (result.item[i].DeviceCategory == "INTEGRATED" && result.item[i].DeviceTypeID == 1002) {

                        if (result.item[i].Slots != null) {
                            $.each(result.item[i].Slots, function (p) {
                                var temp = result.item[i].Slots[p].LatestData.Close;
                                var valueUnit = result.item[i].Slots[p].ValueUnit;

                                if (result.item[i].Slots[p].SlotID == 2) //风向特别处理
                                {
                                    temp = windDirectioin(result.item[i].Slots[p].LatestData.Close);
                                    $("#" + result.item[i].DeviceID + result.item[i].Slots[p].SlotID + ">div").eq(1).html(temp);
                                }
                                else {
                                    $("#" + result.item[i].DeviceID + result.item[i].Slots[p].SlotID + ">div").eq(1).html(temp + "<br/>" + valueUnit);
                                }
                            });
                        }
                    }
                        //水肥机
                    else if (result.item[i].DeviceCategory == "INTEGRATED" && result.item[i].DeviceTypeID == 2102) {
                        $(".water_main").css("display", "block").html("");
                        var temp = "";
                        var h = "<img src=\"/images/h1.jpg\" alt=\"\" class=\"h\">";
                        var t1 = true;
                        var t2 = true;
                        var t3 = true;
                        var t4 = true;
                        if (result.item[i].Slots != null) {
                            $.each(result.item[i].Slots, function (p) {
                                if (result.item[i].Slots[p].SlotID == 13) {
                                    if (NullEmpty(result.item[i].Slots[p].LatestData.Close) == 0) {
                                        temp += "<img src=\"/images/t1.png\" alt=\"\" class=\"t1\">";
                                        temp += "<p class=\"num1 spe\">1</p>";
                                        temp += "<img src=\"/images/g1.png\" alt=\"\" class=\"g1\">";
                                        t1 = false;
                                    }
                                    else {
                                        temp += "<img src=\"/images/t2.png\" alt=\"\" class=\"t1\">";
                                        temp += "<p class=\"num1\">1</p>";
                                        temp += "<img src=\"/images/g2.png\" alt=\"\" class=\"g1\">";
                                    }
                                }
                                if (result.item[i].Slots[p].SlotID == 14) {
                                    if (NullEmpty(result.item[i].Slots[p].LatestData.Close) == 0) {
                                        temp += "<img src=\"/images/t1.png\" alt=\"\" class=\"t2\">";
                                        temp += "<p class=\"num2 spe\">2</p>";
                                        temp += "<img src=\"/images/g1.png\" alt=\"\" class=\"g2\">";
                                        t2 = false;
                                    }
                                    else {
                                        temp += "<img src=\"/images/t2.png\" alt=\"\" class=\"t2\">";
                                        temp += "<p class=\"num2\">2</p>";
                                        temp += "<img src=\"/images/g2.png\" alt=\"\" class=\"g2\">";
                                    }
                                }
                                if (result.item[i].Slots[p].SlotID == 15) {
                                    if (NullEmpty(result.item[i].Slots[p].LatestData.Close) == 0) {
                                        temp += "<img src=\"/images/t1.png\" alt=\"\" class=\"t3\">";
                                        temp += "<p class=\"num3 spe\">3</p>";
                                        temp += "<img src=\"/images/g1.png\" alt=\"\" class=\"g3\">";
                                        t3 = false;
                                    }
                                    else {
                                        temp += "<img src=\"/images/t2.png\" alt=\"\" class=\"t3\">";
                                        temp += "<p class=\"num3\">3</p>";
                                        temp += "<img src=\"/images/g2.png\" alt=\"\" class=\"g3\">";
                                    }
                                }
                                if (result.item[i].Slots[p].SlotID == 16) {
                                    if (NullEmpty(result.item[i].Slots[p].LatestData.Close) == 0) {
                                        temp += "<img src=\"/images/t1.png\" alt=\"\" class=\"t4\">";
                                        temp += "<p class=\"num4 spe\">4</p>";
                                        temp += "<img src=\"/images/g1.png\" alt=\"\" class=\"g4\">";
                                        t4 = false;
                                    }
                                    else {
                                        temp += "<img src=\"/images/t2.png\" alt=\"\" class=\"t4\">";
                                        temp += "<p class=\"num4\">4</p>";
                                        temp += "<img src=\"/images/g2.png\" alt=\"\" class=\"g4\">";
                                    }

                                }
                                if (result.item[i].Slots[p].SlotID == 6) {
                                    temp += "<div class=\"total_s\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                    temp += "<h2>今日总用肥量</h2>";
                                    temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                    temp += "</div>";
                                }
                                if (result.item[i].Slots[p].SlotID == 5) {
                                    temp += "<div class=\"total_f\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                    temp += "<h2>今日总用水量</h2>";
                                    temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                    temp += "</div>";
                                }
                                if (result.item[i].Slots[p].SlotID == 7) {
                                    temp += "<div class=\"total_f1\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                    temp += "<h3>今日用肥量</h3>";
                                    temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                    temp += "</div>";
                                }
                                if (result.item[i].Slots[p].SlotID == 8) {
                                    temp += "<div class=\"total_f2\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                    temp += "<h3>今日用肥量</h3>";
                                    temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                    temp += "</div>";
                                }
                                if (result.item[i].Slots[p].SlotID == 9) {
                                    temp += "<div class=\"total_f3\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                    temp += "<h3>今日用肥量</h3>";
                                    temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                    temp += "</div>";
                                }
                                if (result.item[i].Slots[p].SlotID == 10) {
                                    temp += "<div class=\"total_f4\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                    temp += "<h3>今日用肥量</h3>";
                                    temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                    temp += "</div>";
                                }
                                if (result.item[i].Slots[p].SlotID == 1) {
                                    temp += "<div class=\"total_z1\">";
                                    temp += "<h4>PH值</h2>";
                                    temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                    temp += "</div>";
                                }
                                if (result.item[i].Slots[p].SlotID == 2) {
                                    temp += "<div class=\"total_z2\">";
                                    temp += "<h4>EC值</h2>";
                                    temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                    temp += "</div>";
                                }
                            });
                        }
                        var l = "<img src=\"/images/l5.png\" alt=\"\" class=\"l\">";
                        if (t1)
                            l = "<img src=\"/images/l4.png\" alt=\"\" class=\"l\">";
                        else if (t2)
                            l = "<img src=\"/images/l3.png\" alt=\"\" class=\"l\">";
                        else if (t3)
                            l = "<img src=\"/images/l2.png\" alt=\"\" class=\"l\">";
                        else if (t4)
                            l = "<img src=\"/images/l1.png\" alt=\"\" class=\"l\">";
                        temp += l;
                        if (t1 || t2 || t3 || t4)
                            h = "<img src=\"/images/h2.gif\" alt=\"\" class=\"h\">";
                        temp = h + temp;
                        $(".water_main").append(temp);
                    }
                    else if (result.item[i].DeviceCategory == "CONTROLLER") {
                        var Device = "";
                        //开关停
                        if (result.item[i].DeviceTypeID == 13) {
                            Device += "<li id=\"" + result.item[i].DeviceID + "\">";
                            Device += "<div style=\"display:table;\">";
                            //wjw 2016-10-14
                            //Device += "<p class=\"left\">" + result.item[i].DeviceName.substring(0, 5) + "</p>";
                            Device += "<p class=\"\" style=\"display:table-cell;line-height:20px;vertical-align: middle;\">" + result.item[i].DeviceName + "</p>";
                            Device += "<span class=\"imgs2 right\">";
                            Device += "<i></i>";
                            if (result.item[i].Slots[0].LatestData.Close == 1) {//开
                                Device += "<span class=\"open isopen\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                Device += "<span class=\"stop s\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                Device += "<span class=\"close c\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                            }
                            if (result.item[i].Slots[0].LatestData.Close == 2) {//关
                                Device += "<span class=\"open o\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                Device += "<span class=\"stop s\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                Device += "<span class=\"close isclose\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                            }
                            if (result.item[i].Slots[0].LatestData.Close == 3) {//停
                                Device += "<span class=\"open o\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                Device += "<span class=\"stop isstop\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                Device += "<span class=\"close c\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                            }
                            Device += "</span>";
                            Device += "</div>";
                            Device += "</li>";
                        }
                        if (result.item[i].DeviceTypeID == 14) {
                            Device += "<li id=\"" + result.item[i].DeviceID + "\">";
                            Device += "<div style=\"display:table;\">";
                            //wjw 2016-10-14
                            //Device += "<p class=\"left\">" + result.item[i].DeviceName.substring(0, 5) + "</p>";
                            Device += "<p class=\"\" style=\"display:table-cell;line-height:20px;vertical-align: middle;\">" + result.item[i].DeviceName + "</p>";
                            Device += "<span class=\"imgs right\">";
                            Device += "<i></i>";
                            if (result.item[i].Slots[0].LatestData.Close == 1) {//开
                                Device += "<span class=\"open isopen\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                Device += "<span class=\"close c\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                            }
                            if (result.item[i].Slots[0].LatestData.Close == 0) {//关
                                Device += "<span class=\"open o\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                Device += "<span class=\"close isclose\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                            }
                            Device += "</span>";
                            Device += "</div>";
                            Device += "</li>";
                        }

                        if ((k + 1) % 2 == 0)
                            $("#tabNav2").append(Device);
                        else
                            $("#tabNav").append(Device);
                        k++;
                    }
                });
            },
            complete: function () {
                //console.log("complete")
                layer.close(layer_i);
            }
        });
    }
    function GetArea(areaId, userId) {
        $(".num").css("display", "none");
        $(".water").css("display", "none");
        $(".temp").css("display", "none")
        $(".content").css("display", "none");
        var DeviceSerial = $("#Cameras").find("option:selected").attr("deviceserial");
        var ChannelNo = $("#Cameras").find("option:selected").attr("channelno");
        DeviceSerial = 0;
        ChannelNo = 0;
        $(".water_main").css("display", "none").html("");
        $("#DeviceList").html("");
        $("#Cameras").html("");
        $("#tabNav").html("");
        $("#tabNav2").html("");
        $(".temp_infor").html("");
        $("#playercontainer_wrapper").remove();
        $("#playercontainer").remove();
        $(".video_img").append("<div id=\"playercontainer\"></div>");
        if (DeviceSerial == undefined)
            DeviceSerial = 0;
        if (ChannelNo == undefined)
            ChannelNo = 0;
        $.ajax({
            beforeSend: function () { layer_i = layer.msg('加载中...', { icon: 16, shade: 0.01, time: 60 * 1000 }); },
            url: '/Iot/Home/AreaTree_NodeMouse',
            timeout: 60000,
            data: { AreaID: areaId, DeviceSerial: DeviceSerial, ChannelNo: ChannelNo, UserId: userId },
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (typeof (result.Msg) != "undefined") {
                    location.href = '/Login/Login';
                }
                console.log("result:" + result);
                var j = 0;
                var k = 0;
                if (result.item != null) {
                    $.each(result.item, function (i) {
                        if (result.item[i].DeviceCategory == "SENSOR") {
                            if (result.item[i].DeviceTypeID != 1002) {
                                $(".num").css("display", "block");
                                var css = "num_info";
                                if ((j + 1) % 5 == 0)
                                    css = "num_info spe";
                                var error = "146133";
                                if (result.item[i].Slots[0].ThreatLevel != -1 && result.item[i].Slots[0].ThreatLevel != 0)
                                    error = "ff0000";
                                var data = result.item[i].Slots[0].LatestData.Close == null ? "<p class=\"temperature\" SlotID=\"" + result.item[i].Slots[0].SlotID + "\" id=\"" + result.item[i].DeviceID + "\" type=\"" + result.item[i].DeviceTypeID + "\">暂无数据</p>" : "<p class=\"temperature\" id=\"" + result.item[i].DeviceID + "\" SlotID=\"" + result.item[i].Slots[0].SlotID + "\" type=\"" + result.item[i].DeviceTypeID + "\" style=\"color: #" + error + ";\">" + NullEmpty(result.item[i].Slots[0].LatestData.Open) + "<b>" + NullEmpty(result.item[i].Slots[0].ValueUnit) + "</b></p><p class=\"condition\" style=\"color: #" + error + ";\">" + NullEmpty(result.item[i].Slots[0].ThreatName) + "</p>";
                                var setting = $("#a" + result.item[i].DeviceID).text();
                                var b = result.item[i].Slots[0].SensorTypeID;
                                var img = '/images/sensor_white/s' + b + '.png';
                                var Differ = ((result.item[i].Slots[0].LatestData.Close * 1000 - result.item[i].Slots[0].LatestData.Open * 1000) / 1000).toFixed(2);
                                var Device = "";
                                Device += "<li class=\"" + css + "\" id=\"" + result.item[i].DeviceID + "\">";
                                Device += "<div class=\"num_top\">";
                                Device += "<img src=\"" + img + "\" width=\"36\" alt=\"\" />";
                                Device += "<p>" + result.item[i].DeviceName + "</p>";
                                Device += "</div>";
                                Device += "<div class=\"qushi\">";

                                if (Differ >= 0) {
                                    Device += "<p>" + SensorNumException(Differ) + "</p>";
                                    Device += "<img src=\"/images/IotHome/rup_icon.png\" height=\"9\" width=\"17\" alt=\"\" />";
                                }
                                else {
                                    Device += "<p style=\"color: #146133;\">" + SensorNumException(Differ) + "</p>";
                                    Device += "<img src=\"/images/IotHome/gdown_icon.png\" height=\"9\" width=\"17\" alt=\"\" />";
                                }
                                Device += "</div>";
                                Device += "<P class=\"tem\" style=\"color: #" + error + ";\" >" + SensorNumException(result.item[i].Slots[0].LatestData.Close) + "<i>" + NullEmpty(result.item[i].Slots[0].ValueUnit) + "</i></P>";

                                var EnableHigh = $("#" + result.item[i].DeviceID + result.item[i].Slots[0].ThreatName).attr("enablehigh");
                                var HighValue = $("#" + result.item[i].DeviceID + result.item[i].Slots[0].ThreatName).attr("highvalue");
                                var EnableLow = $("#" + result.item[i].DeviceID + result.item[i].Slots[0].ThreatName).attr("enablelow");
                                var LowValue = $("#" + result.item[i].DeviceID + result.item[i].Slots[0].ThreatName).attr("lowvalue");

                                if (EnableHigh == undefined || EnableHigh == 0)
                                    HighValue = "";
                                if (EnableLow == undefined || LowValue == 0)
                                    LowValue = "";

                                if (HighValue != "" && LowValue != "") {
                                    var hv = parseInt(HighValue);
                                    var lv = parseInt(LowValue);
                                    Device += "<p class=\"tiao\">";
                                    if (hv < lv) {
                                        Device += "<span class=\"t1\">" + HighValue + "</span>";
                                        Device += "<span class=\"t2\">" + LowValue + "</span>";
                                    }
                                    else {
                                        Device += "<span class=\"t1\">" + LowValue + "</span>";
                                        Device += "<span class=\"t2\">" + HighValue + "</span>";
                                    }
                                    Device += "</p>";
                                }
                                else {
                                    //2017-7-12 xyc 报警信息显示不正确
                                    if (LowValue != "" || HighValue != "") {
                                            Device += "<p class=\"tiao\">";
                                            Device += "<span class=\"t1\">" + HighValue + "</span>";
                                            Device += "<span class=\"t2\">" + LowValue + "</span>";
                                            Device += "</p>";
                                    }
                                    else {
                                        Device += "<p class=\"tiao\" style=\"background-color:white\">";
                                        Device += "<span class=\"t1\">" + LowValue + "</span>";
                                        Device += "<span class=\"t2\">" + HighValue + "</span>";
                                        Device += "</p>";
                                    }
                                }
                                Device += "<p class=\"normal\" style=\"color: #" + error + ";\" >" + NullEmpty(result.item[i].Slots[0].ThreatName) + "</p>";
                                Device += "<p class=\"time\" style=\"font-size:medium;\">" + NullEmpty(result.item[i].Slots[0].LatestData.Time) + "</p>";
                                Device += "<div class=\"btn\">";
                                Device += "<button class=\"left\" onclick=\"SetSetting()\">报警设置</button>";
                                Device += "<button class=\"right\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[0].SlotID + "','" + result.item[i].DeviceTypeID + "')\" >历史数据</button>";
                                Device += "</div>";
                                Device += "</li> ";
                                $("#DeviceList").append(Device);
                                j++;
                            }
                        }
                            //气象站
                        else if (result.item[i].DeviceCategory == "INTEGRATED" && result.item[i].DeviceTypeID == 1002) {
                            $(".temp").css("display", "block");
                            var temp = "";
                            temp += "<div class=\"temp_l\">";
                            if (result.item[i].Slots != null) {
                                $.each(result.item[i].Slots, function (p) {

                                    temp += "<div id=\"" + result.item[i].DeviceID + result.item[i].Slots[p].SlotID + "\" class=\"tem_icon tem_icon" + (p + 1) + " clearfix\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].Slots[p].SlotName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "');\">";
                                    temp += "<div class=\"left i1\">";
                                    var img2 = '/images/IotHome/ss' + result.item[i].Slots[p].SensorTypeID + '.png';
                                    temp += "<div class=\"m1\"><img src=\"" + img2 + "\" height=\"25\" width=\"38\" alt=\"\"></div>";
                                    temp += "<p>" + result.item[i].Slots[p].SlotName + "</p>";
                                    temp += "</div>";
                                    if (result.item[i].Slots[p].SlotID == 2) //风向特别处理
                                    {
                                        temp += "<div class=\"left i2\">";
                                        temp += windDirectioin(result.item[i].Slots[p].LatestData.Close);
                                    }
                                    else {
                                        temp += "<div class=\"left i2 i3\">";
                                        temp += result.item[i].Slots[p].LatestData.Close;
                                        temp += "<br/>" + result.item[i].Slots[p].ValueUnit;
                                    }

                                    temp += "</div>";
                                    temp += "</div>";
                                });
                            }
                            $(".temp_infor").append(temp);
                        }
                            //水肥机
                        else if (result.item[i].DeviceCategory == "INTEGRATED" && result.item[i].DeviceTypeID == 2102) {
                            $(".water").css("display", "block");
                            $(".water_main").css("display", "block").html("");
                            var temp = "";
                            var h = "<img src=\"/images/h1.jpg\" alt=\"\" class=\"h\">";
                            var t1 = true;
                            var t2 = true;
                            var t3 = true;
                            var t4 = true;
                            if (result.item[i].Slots != null) {
                                $.each(result.item[i].Slots, function (p) {
                                    if (result.item[i].Slots[p].SlotID == 13) {
                                        if (NullEmpty(result.item[i].Slots[p].LatestData.Close) == 0) {
                                            temp += "<img src=\"/images/t1.png\" alt=\"\" class=\"t1\">";
                                            temp += "<p class=\"num1 spe\">1</p>";
                                            temp += "<img src=\"/images/g1.png\" alt=\"\" class=\"g1\">";
                                            t1 = false;
                                        }
                                        else {
                                            temp += "<img src=\"/images/t2.png\" alt=\"\" class=\"t1\">";
                                            temp += "<p class=\"num1\">1</p>";
                                            temp += "<img src=\"/images/g2.png\" alt=\"\" class=\"g1\">";
                                        }
                                    }
                                    if (result.item[i].Slots[p].SlotID == 14) {
                                        if (NullEmpty(result.item[i].Slots[p].LatestData.Close) == 0) {
                                            temp += "<img src=\"/images/t1.png\" alt=\"\" class=\"t2\">";
                                            temp += "<p class=\"num2 spe\">2</p>";
                                            temp += "<img src=\"/images/g1.png\" alt=\"\" class=\"g2\">";
                                            t2 = false;
                                        }
                                        else {
                                            temp += "<img src=\"/images/t2.png\" alt=\"\" class=\"t2\">";
                                            temp += "<p class=\"num2\">2</p>";
                                            temp += "<img src=\"/images/g2.png\" alt=\"\" class=\"g2\">";
                                        }
                                    }
                                    if (result.item[i].Slots[p].SlotID == 15) {
                                        if (NullEmpty(result.item[i].Slots[p].LatestData.Close) == 0) {
                                            temp += "<img src=\"/images/t1.png\" alt=\"\" class=\"t3\">";
                                            temp += "<p class=\"num3 spe\">3</p>";
                                            temp += "<img src=\"/images/g1.png\" alt=\"\" class=\"g3\">";
                                            t3 = false;
                                        }
                                        else {
                                            temp += "<img src=\"/images/t2.png\" alt=\"\" class=\"t3\">";
                                            temp += "<p class=\"num3\">3</p>";
                                            temp += "<img src=\"/images/g2.png\" alt=\"\" class=\"g3\">";
                                        }
                                    }
                                    if (result.item[i].Slots[p].SlotID == 16) {
                                        if (NullEmpty(result.item[i].Slots[p].LatestData.Close) == 0) {
                                            temp += "<img src=\"/images/t1.png\" alt=\"\" class=\"t4\">";
                                            temp += "<p class=\"num4 spe\">4</p>";
                                            temp += "<img src=\"/images/g1.png\" alt=\"\" class=\"g4\">";
                                            t4 = false;
                                        }
                                        else {
                                            temp += "<img src=\"/images/t2.png\" alt=\"\" class=\"t4\">";
                                            temp += "<p class=\"num4\">4</p>";
                                            temp += "<img src=\"/images/g2.png\" alt=\"\" class=\"g4\">";
                                        }

                                    }
                                    if (result.item[i].Slots[p].SlotID == 6) {
                                        temp += "<div class=\"total_s\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                        temp += "<h2>今日总用肥量</h2>";
                                        temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                        temp += "</div>";
                                    }
                                    if (result.item[i].Slots[p].SlotID == 5) {
                                        temp += "<div class=\"total_f\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                        temp += "<h2>今日总用水量</h2>";
                                        temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                        temp += "</div>";
                                    }
                                    if (result.item[i].Slots[p].SlotID == 7) {
                                        temp += "<div class=\"total_f1\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                        temp += "<h3>今日用肥量</h3>";
                                        temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                        temp += "</div>";
                                    }
                                    if (result.item[i].Slots[p].SlotID == 8) {
                                        temp += "<div class=\"total_f2\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                        temp += "<h3>今日用肥量</h3>";
                                        temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                        temp += "</div>";
                                    }
                                    if (result.item[i].Slots[p].SlotID == 9) {
                                        temp += "<div class=\"total_f3\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                        temp += "<h3>今日用肥量</h3>";
                                        temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                        temp += "</div>";
                                    }
                                    if (result.item[i].Slots[p].SlotID == 10) {
                                        temp += "<div class=\"total_f4\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                        temp += "<h3>今日用肥量</h3>";
                                        temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                        temp += "</div>";
                                    }
                                    if (result.item[i].Slots[p].SlotID == 1) {
                                        temp += "<div class=\"total_z1\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                        temp += "<h4>PH值</h2>";
                                        temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                        temp += "</div>";
                                    }
                                    if (result.item[i].Slots[p].SlotID == 2) {
                                        temp += "<div class=\"total_z2\" onclick=\"GetHistory('" + result.item[i].DeviceID + "','" + result.item[i].DeviceName + "','" + result.item[i].Slots[p].SlotID + "','" + result.item[i].DeviceTypeID + "')\">";
                                        temp += "<h4>EC值</h2>";
                                        temp += "<i>" + NullEmpty(result.item[i].Slots[p].LatestData.Close) + result.item[i].Slots[p].ValueUnit + "</i>";
                                        temp += "</div>";
                                    }
                                });
                            }
                            var l = "<img src=\"/images/l5.png\" alt=\"\" class=\"l\">";
                            if (t1)
                                l = "<img src=\"/images/l4.png\" alt=\"\" class=\"l\">";
                            else if (t2)
                                l = "<img src=\"/images/l3.png\" alt=\"\" class=\"l\">";
                            else if (t3)
                                l = "<img src=\"/images/l2.png\" alt=\"\" class=\"l\">";
                            else if (t4)
                                l = "<img src=\"/images/l1.png\" alt=\"\" class=\"l\">";
                            temp += l;
                            if (t1 || t2 || t3 || t4)
                                h = "<img src=\"/images/h2.gif\" alt=\"\" class=\"h\">";
                            temp = h + temp;
                            $(".water_main").append(temp);
                        }

                        else if (result.item[i].DeviceCategory == "CONTROLLER") {
                            $(".content").css("display", "block");
                            var Device = "";
                            //开关停
                            if (result.item[i].DeviceTypeID == 13) {
                                Device += "<li id=\"" + result.item[i].DeviceID + "\">";
                                Device += "<div style=\"display:table;\">";
                                //wjw 2016-10-14
                                //Device += "<p class=\"left\">" + result.item[i].DeviceName.substring(0, 5) + "</p>";
                                Device += "<p class=\"\" style=\"display:table-cell;line-height:20px;vertical-align: middle;\">" + result.item[i].DeviceName + "</p>";
                                Device += "<span class=\"imgs2 right\">";
                                Device += "<i></i>";
                                if (result.item[i].Slots[0].LatestData.Close == 1) {//开
                                    Device += "<span class=\"open isopen\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                    Device += "<span class=\"stop s\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                    Device += "<span class=\"close c\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                }
                                if (result.item[i].Slots[0].LatestData.Close == 2) {//关
                                    Device += "<span class=\"open o\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                    Device += "<span class=\"stop s\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                    Device += "<span class=\"close isclose\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                }
                                if (result.item[i].Slots[0].LatestData.Close == 3) {//停
                                    Device += "<span class=\"open o\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                    Device += "<span class=\"stop isstop\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                    Device += "<span class=\"close c\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                }
                                Device += "</span>";
                                Device += "</div>";
                                Device += "</li>";
                            }
                            if (result.item[i].DeviceTypeID == 14) {
                                Device += "<li id=\"" + result.item[i].DeviceID + "\">";
                                Device += "<div style=\"display:table;\">";
                                //wjw 2016-10-14
                                //Device += "<p class=\"left\">" + result.item[i].DeviceName.substring(0, 5) + "</p>";
                                Device += "<p class=\"\" style=\"display:table-cell;line-height:20px;vertical-align: middle;\">" + result.item[i].DeviceName + "</p>";
                                Device += "<span class=\"imgs right\">";
                                Device += "<i></i>";
                                if (result.item[i].Slots[0].LatestData.Close == 1) {//开
                                    Device += "<span class=\"open isopen\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                    Device += "<span class=\"close c\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                }
                                if (result.item[i].Slots[0].LatestData.Close == 0) {//关
                                    Device += "<span class=\"open o\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                    Device += "<span class=\"close isclose\" DeviceID=\"" + result.item[i].DeviceID + "\" SlotType=\"" + result.item[i].Slots[0].SlotID + "\"></span>";
                                }
                                Device += "</span>";
                                Device += "</div>";
                                Device += "</li>";
                            }
                            if ((k + 1) % 2 == 0)
                                $("#tabNav2").append(Device);
                            else
                                $("#tabNav").append(Device);
                            k++;
                        }
                    });
                }
                if (k == 0) {
                    $("#controller").css("height", "0px");
                }
                else {
                    $("#controller").css("height", "375px");
                }
                $("#sensor").html(j);
                GetHistoryOperation();
                $(".video_img").css("height", "0px");
                $.each(result.Cameras, function (i) {
                    $(".content").css("display", "block");
                    $(".video_img").css("height", "365px");
                    if (i == 0) {
                        SetPlayer(result.Cameras[i].LiveUrl);
                    }
                    var temp = "<option value=\"" + result.Cameras[i].LiveUrl + "\" ChannelNo=\"" + result.Cameras[i].ChannelNo + "\" DeviceSerial=\"" + result.Cameras[i].DeviceSerial + "\">" + result.Cameras[i].CameraName + "</option>";
                    $("#Cameras").append(temp);

                });
                $("#controllercount").html(k);
                layer.close(layer_i);
            },
            complete: function () {

            }
        });
    }

    function Test() {
        layer.closeAll();
        var url = '/Iot/Home/History' + '?id=' + DeviceId + "&type=" + TypeID + "&slotid=" + SlotId + "&UserId=" + GetUserId();
        window.open(url);
        //LoadAction(1, url);
    }
    //摄像头
    function SetPlayer(url) {
        var flashvars = {
            f: '' + url + '',
            c: '1',
            p: '1'
        };
        var params = { bgcolor: '#FFF', allowFullScreen: true, allowScriptAccess: 'always', wmode: 'transparent' };
        CKobject.embedSWF("/Scripts/ckplayer/ckplayer.swf", "playercontainer", "video", "550px", "365px", flashvars, params);
    }
    function GetHistory(deviceId, name, slotId, deviceTypeId) {
        DeviceId = deviceId;
        SlotId = slotId;
        TypeID = deviceTypeId;
        var width = (echarswidth + 4) + "px";
        var height = $(window).height() / 2 + "px";
        $("#sensorname").text(name);
        var id = deviceId + ":" + slotId + ",";
        layer.open({
            title: false,
            type: 1,
            closeBtn: 0,
            shadeClose: true,
            area: [width, ''], //宽高
            content: $('#dialog_add')
        });
        SetCharts(id);

    }

    function DownLoad() {
        location.href = "/Iot/Home/DownLoad" + "?deviceId=" + ExcelDeviceId + "&day=-7&areaId=" + $("#area").val() + "&userId=" + GetUserId();
    }

    function SetCharts(deviceId) {
        ExcelDeviceId = deviceId;
        var data = -7;
        var deviceId = deviceId;
        var Unit = "";
        var XAxisData = [];
        var series = [];
        var legendData = [];
        $.ajax({
            url: "/Iot/Home/DeviceHistory",
            type: "post",
            dataType: "json",
            async: false,
            data: {
                action: "SearchDeviceHistory",
                deviceId: deviceId,
                day: data,
                dataType: "5",
                startDate: "",
                endDate: "",
                maxCount: "5"
            },
            success: function (re) {
                if (typeof (re.Msg) != "undefined") {
                    location.href = '/Login/Login';
                }
                Unit = re.Unit;
                $.each(re.XAxisData, function (i) {
                    XAxisData.push(re.XAxisData[i]);
                });
                $.each(re.Series, function (i) {
                    var data = [];
                    $.each(re.Series[i].Data, function (k) {
                        data.push(re.Series[i].Data[k].Open);
                    });
                    series.push(new SetList(re.Series[i].DeviceName, 'line', data));
                    legendData.push(re.Series[i].DeviceName);
                });
            }
        });
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        //指定图表的配置项和数据
        var option = {
            title: {
                text: ''
            },
            toolbox: {
                show: true,
                feature: {
                    myTool2: {
                        show: true,
                        title: '导出Excel                     ',
                        icon: 'image://../images/excel.jpg',
                        onclick: function () {
                            DownLoad();
                        }
                    }
                }
            },
            dataZoom: [
            {
                type: 'slider',
                show: true,
                xAxisIndex: [0],
                start: 75,
                end: 100
            },
            {
                type: 'inside',
                xAxisIndex: [0],
                start: 75,
                end: 100
            }
            ],
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: legendData
            },
            xAxis: {
                name: '时间',
                type: 'category',
                boundaryGap: false,
                data: XAxisData,
                splitLine: {
                    show: false
                }
            },
            yAxis: {
                name: Unit,
                type: 'value',
                splitLine: {
                    show: false
                }
            },
            series: series
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    function SetList(name, type, data) {
        this.name = name;
        this.type = type;
        this.data = data;
    }
    function SetSetting() {
        window.open('/Settings/Alarm');
    }
    function GetHistoryOperation() {
        //var tabNav = document.getElementById('tabNav').getElementsByTagName('li');
        //var tabNav2 = document.getElementById('tabNav2').getElementsByTagName('li');
        //var tabList = document.getElementById('tabList').getElementsByTagName('li');
        ////右边效果
        //for (var i = 0; i < tabNav2.length; i++) {
        //    tabNav2[i].index = i;
        //    tabNav2[i].onclick = function () {

        //        $(".notice-bd").css("display", "block");
        //        if ($("#tabNav li").length > 6) {
        //            $(".notice-bd").css("right", "299px");
        //        }
        //        else {
        //            $(".notice-bd").css("right", "316px");
        //        }
        //        for (var j = 0; j < tabNav2.length; j++) {
        //            tabNav2[j].className = '';
        //            $(tabNav2[j]).find("div").css("border", "1px solid #9dafb0");
        //            //tabList[j].className = '';
        //        }
        //        $(this).find("div").css("border", "0px solid #9dafb0");

        //        for (var j = 0; j < tabNav.length; j++) {
        //            tabNav[j].className = '';
        //            //tabList[j].className = '';
        //        }
        //        this.className = 'current2';
        //        //$(this).css("border-style", "solid solid solid none");
        //        //$(this).css("border-width", "2px 2px 2px 0");
        //        //$(this).css("border-color", "#2798b0");
        //        //tabList[this.index].className = 'current';
        //        tabList[0].className = 'current';
        //        if ($("#tabNav li").length > 6) {
        //            $(this).width(299);
        //            var height = $("#controller").scrollTop();
        //            var b = $(this).position().top;
        //            if (b < 0) {
        //                tag2 = 1;
        //                if ((b + height) > 0) {
        //                    $("#controller").scrollTop((b + height));
        //                    $(".notice-bd").css("top", (b + height));
        //                }
        //                else {
        //                    $("#controller").scrollTop(0);
        //                    $(".notice-bd").css("top", 0);
        //                }
        //            }
        //            else if (tag2 == 0 && (this.index + 1) == $("#tabNav2 li").length) {

        //            }
        //            else if (b > 300) {
        //                if ((this.index + 1) == $("#tabNav2 li").length) {
        //                    tag2 = 0;
        //                }
        //                $(".notice-bd").css("top", 60 + height);
        //            }

        //            else {
        //                tag2 = 1;
        //                $(".notice-bd").css("top", height);
        //            }
        //        }
        //    }
        //}

        ////左边效果
        //for (var i = 0; i < tabNav.length; i++) {
        //    tabNav[i].index = i;
        //    tabNav[i].onclick = function () {
        //        $(".notice-bd").css("right", "0px");
        //        $(".notice-bd").css("display", "block");
        //        for (var j = 0; j < tabNav.length; j++) {
        //            tabNav[j].className = '';
        //            //tabList[j].className = '';
        //        }
        //        for (var j = 0; j < tabNav2.length; j++) {
        //            tabNav2[j].className = '';
        //            $(tabNav2[j]).find("div").css("border", "1px solid #9dafb0");
        //            //tabList[j].className = '';
        //        }
        //        this.className = 'current';
        //        //tabList[this.index].className = 'current';
        //        tabList[0].className = 'current';
        //        if ($("#tabNav li").length > 6) {
        //            $(this).width(299);
        //            var height = $("#controller").scrollTop();
        //            var b = $(this).position().top;
        //            if (b < 0) {
        //                tag = 1;
        //                if ((b + height) > 0) {
        //                    $("#controller").scrollTop((b + height));
        //                    $(".notice-bd").css("top", (b + height));
        //                }
        //                else {
        //                    $("#controller").scrollTop(0);
        //                    $(".notice-bd").css("top", 0);
        //                }
        //            }
        //            else if (tag == 0 && (this.index + 1) == $("#tabNav li").length) {

        //            }
        //            else if (b > 300) {
        //                if ((this.index + 1) == $("#tabNav li").length) {
        //                    tag = 0;
        //                }
        //                $(".notice-bd").css("top", 60 + height);
        //            }

        //            else {
        //                tag = 1;
        //                $(".notice-bd").css("top", height);
        //            }
        //        }
        //    }
        //}
    }


    function ControlRelay(DeviceID, Action, SlotType) {
        var temp = $("#" + DeviceID).html();
        var len = $("#" + DeviceID + ">div>span>span").length;
        var string = "";
        hideOperateHistory();
        switch (Action) {
            case "OPEN":
                if (len == 2) {
                    string = "正在打开...";
                }
                if (len == 3) {
                    string = "正在打开...";
                }
                operateCategory = 1;
                break;
            case "CLOSE":
                if (len == 2) {
                    string = "正在关闭...";
                }
                if (len == 3) {
                    string = "正在关闭...";
                }
                operateCategory = 2;
                break;
            case "STOP":
                operateCategory = 3;
                string = "正在停止...";
                break;
            default:
                break;
        }
        var str = $("#" + DeviceID + ">div");
        var dname = $("#" + DeviceID + ">div>p").text();
        $.ajax({
            beforeSend: function () {
                str.block({ message: string });
            },
            url: '/Iot/Home/ControlRelay',
            data: {
                DeviceID: DeviceID,
                DeviceName: dname,
                OCategory: operateCategory,
                Ccategory: "1",
                AreaId: $("#area").val(),
                AreaName: $("#area").find("option:selected").text(),
                GroupId: $("#area").find("option:selected").attr("groupid"),
                GroupName: $("#area").find("option:selected").attr("groupname"),
                Action: Action,
                SlotType: SlotType
            },
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (typeof (result.Msg) != "undefined") {
                    location.href = '/Login/Login';
                }
                if (result != "error") { //操作成功
                    switch (Action) {
                        case "OPEN":
                            if (len == 2) {
                                $("#" + DeviceID + ">div>span>span").eq(1).removeClass("isclose").addClass("c");
                                $("#" + DeviceID + ">div>span>span").eq(0).addClass("isopen").removeClass("o");
                            }
                            if (len == 3) {
                                $("#" + DeviceID + ">div>span>span").eq(2).removeClass("isclose").addClass("c");
                                $("#" + DeviceID + ">div>span>span").eq(1).removeClass("isstop").addClass("s");
                                $("#" + DeviceID + ">div>span>span").eq(0).addClass("isopen").removeClass("o");
                            }
                            break;
                        case "CLOSE":
                            if (len == 2) {
                                $("#" + DeviceID + ">div>span>span").eq(1).addClass("isclose").removeClass("c");
                                $("#" + DeviceID + ">div>span>span").eq(0).removeClass("isopen").addClass("o");
                            }
                            if (len == 3) {
                                $("#" + DeviceID + ">div>span>span").eq(2).addClass("isclose").removeClass("c");
                                $("#" + DeviceID + ">div>span>span").eq(1).removeClass("isstop").addClass("s");
                                $("#" + DeviceID + ">div>span>span").eq(0).removeClass("isopen").addClass("o");
                            }
                            break;
                        case "STOP":
                            $("#" + DeviceID + ">div>span>span").eq(2).removeClass("isclose").addClass("c");
                            $("#" + DeviceID + ">div>span>span").eq(1).addClass("isstop").removeClass("s");
                            $("#" + DeviceID + ">div>span>span").eq(0).removeClass("isopen").addClass("o");
                            break;
                        default:
                            break;
                    }
                }
                else {
                    //console.log(temp)
                    //$("#" + DeviceID).html(temp);
                    layer.msg('操作失败', {
                        icon: 2,
                        time: 2000
                    });
                }
            },
            complete: function () { str.unblock(); }
        });
    }
    function GetControllerLog(id) {
        var $logTable = $("#controllerlog");
        $logTable.html("<tr><th>操作人</th><th>操作</th><th>时间</th><th>结果</th></tr>");
        for (var i = 0; i < 7; i++) {
            $logTable.append("<tr><td></td><td></td><td></td><td></td></tr>");
        }
        $.ajax({
            url: '/Iot/Home/GetControllerLog',
            data: {
                DeviceID: id
            },
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (typeof (result.Msg) != "undefined") {
                    location.href = '/Login/Login';
                }
                $.each(result, function (i) {
                    var temp = "";
                    temp += "<td>" + result[i].UserName + "</td>";
                    if (result[i].Operation == "OPEN")
                        temp += "<td class=\"green\">开</td>";
                    if (result[i].Operation == "CLOSE")
                        temp += "<td class=\"red\">关</td>";
                    if (result[i].Operation == "STOP")
                        temp += "<td class=\"yellow\">停</td>";
                    temp += "<td>" + result[i].Data + "<br />" + result[i].Data2 + "</td>";
                    temp += "<td>" + (result[i].Result == 1 ? "成功" : "失败") + "</td>";
                    $logTable.find("tr").eq(i + 1).html(temp);
                });
                //factorial();
            }
        });

    }

    function factorial() {
        var num = $("#controllerlog tr").not(":first").length;
        if (num < 7) {
            for (var i = 0; i < 7 - num; i++) {
                $("#controllerlog").find("tr").eq(num).after("<tr><td></td><td></td><td></td></tr>");
            }
        }
    }


    function hideOperateHistory() {
        var tabNav = document.getElementById('tabNav').getElementsByTagName('li');
        var tabNav2 = document.getElementById('tabNav2').getElementsByTagName('li');
        var tabList = document.getElementById('tabList').getElementsByTagName('li');
        for (var j = 0; j < tabNav.length; j++) {
            tabNav[j].className = '';
        }
        for (var j = 0; j < tabNav2.length; j++) {
            tabNav2[j].className = '';
            $(tabNav2[j]).find("div").css("border", "1px solid #9dafb0");
        }
        tabList[0].className = '';
        $(".notice-bd").css("display", "none");
    }

    function NullEmpty(str) {
        if (str == null)
            return "";
        return str;
    }

    //传感器数据超出正常
    function SensorNumException(num) {
        if ((num + "").length > 8)
            return "数据异常";
        return num;
    }
    function GetUserId() {
        return $("#area option:selected").attr("userId");
    }
</script>
<span id="b02b0cbe-95ee-4091-b96f-a68f398ecee1"></span><span id="3c978f68-3fca-4d77-b7a3-e431d4712db6报警" enablehigh="1" highvalue="0.02" enablelow="0" lowvalue="10000"></span><span id="3c978f68-3fca-4d77-b7a3-e431d4712db6正常" enablehigh="0" highvalue="-10000" enablelow="1" lowvalue="0.02"></span><span id="86044502-1427-41a0-bf08-37967e1ddf58报警" enablehigh="1" highvalue="0.05" enablelow="0" lowvalue="10000"></span><span id="86044502-1427-41a0-bf08-37967e1ddf58正常" enablehigh="0" highvalue="-10000" enablelow="1" lowvalue="0.05"></span><span id="0f0771f6-2714-4992-8428-6922802d4912正常" enablehigh="1" highvalue="4" enablelow="0" lowvalue="20"></span><span id="0f0771f6-2714-4992-8428-6922802d4912报警" enablehigh="0" highvalue="-1000" enablelow="1" lowvalue="4"></span></body></html>